<?php
// +----------------------------------------------------------------------
// | snake
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: NickBai <1902822973@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\model;

use think\Db;
use think\Model;

class SystemManager extends Model
{
    const STATUS_COMMENT = 1;
    const STATUS_BAN = 0;

    public static $tableName = 'vote_system_manager';

    public static $statusInfo = [1=>'正常', 2=>'禁用'];

    public function getManagersAll($where, $offset, $limit){
        return Db::table(static::$tableName)->field('id,username,real_name,last_login_ip,last_login_time,loginnum,status')->where($where)->limit($offset.','.$limit)->select();
    }

    public function getCount($where){
        return Db::table(static::$tableName)->where($where)->count();
    }

    public function add($data){
        $data['password'] = md5(md5($data['password']));
        return $this->insert($data) == 1;
    }

    public function edit($data){
        $data['password'] = md5(md5($data['password']));
        return Db::table(static::$tableName)->update($data) == 1;
    }

    public function del($managerId){
        return Db::table(static::$tableName)->update(['id'=>$managerId, 'is_del'=>time()]) == 1;
    }
}
